package com.gatesim;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

public class Connection {

	private Point point;
	private int charge;
	private boolean selected;
	private boolean occupied;
	private Bitmap selection = BitmapFactory.decodeResource(resources, R.drawable.selection);

	protected static final int CONN_ONE_CHARGE = 1;
	protected static final int CONN_ZERO_CHARGE = 0;
	protected static final int CONN_NO_CHARGE = -1;
	
	public static Resources resources;
	
	public Connection(Point p){
		point = p;
		charge = CONN_NO_CHARGE;
		selected = false;
		occupied = false;
	}
	
	//Must be called to get images
	public static void setResources(Resources r){
		resources = r;
	}
	
	public void draw(Canvas c, Resources r) {	
		if(selected)
			c.drawBitmap(selection, point.x - selection.getWidth()/2,
									point.y - selection.getHeight()/2, null);
	}
	
	public Point getPoint(){
		return point;
	}
	
	public void setPoint(int x, int y){
		point.x = x;
		point.y = y;
	}
	
	public void setCharge(int c){
		charge = c;
	}
	
	public int getCharge(){
		return charge;
	}
	
	public boolean isOccupied(){
		return occupied;
	}
	
	public boolean hasCharge(){
		return (charge != CONN_NO_CHARGE);
	}
	
	public boolean isSelected(){
		return selected;
	}
	
	public void select(){
		selected = true;
	}
	
	public void deselect(){
		selected = false;
	}
	
	public void occupy(){
		occupied = true;
	}
    public void unoccupy(){
        occupied = false;
    }
	
	public boolean isInputConnection()	{return false;}
	public boolean isOutputConnection()	{return false;}
	public boolean isVolt()	{return false;}
}
